  import { TOKEN_KEY } from '@/configs'
  import { getStorageSync } from './store'

export const callCloudFunction = (configs, loadingText) => {
  configs.data.token = getStorageSync(TOKEN_KEY)
  return new Promise((resolve, reject) => {
    uni.showLoading({
      title:  loadingText ? loadingText : '加载中'
    })
    uniCloud.callFunction(configs)
    .then(res => {
      uni.hideLoading()
      if (res.result.needLogin) {
        uni.navigateTo({
          url: '/pages/user/login'
        })
        resolve({})
      }
      resolve(res.result)
    })
    .catch(err => {
      uni.hideLoading()
      reject(err)
    })
  })
}